<?php 
use yii\helpers\Html;
use yii\widgets\LinkPager;
use yii\widgets\ActiveForm;
?>
<!-- 权限管理模块 -->
	<div class="check-div">
		<button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#addNode">添加权限</button>
	</div>
	<div class="data-div">
		<div class="row tableHeader">
			<div class="col-xs-1 ">
				I D
			</div>
			<div class="col-xs-2">
				权限名
			</div>
			<div class="col-xs-2">
				控制器
			</div>
			<div class="col-xs-2">
				方法
			</div>
			<div class="col-xs-3">
				描述
			</div>
			<div class="col-xs-2">
				操作
			</div>
		</div>
		<div class="tablebody">
		<?php foreach ($nodeDate as $k => $v) {?>
			<div class="row">
				<div class="col-xs-1 ">
					<?=$v['id'] ?>
				</div>
				<div class="col-xs-2">
					</span><span><?=$v['name'] ?></span>
				</div>
				<div class="col-xs-2">
					<?=$v['controller'] ?>
				</div>
				<div class="col-xs-2">
					<?=$v['action'] ?>
				</div>
				<div class="col-xs-3">
					<?=$v['describe'] ?>
				</div>
				<div class="col-xs-2">
					<button class="btn btn-success btn-xs update" data-toggle="modal" node_id='<?=$v["id"]?>' data-target="#changeNode">修改</button>
					<button class="btn btn-danger btn-xs delete" data-toggle="modal"  node_id='<?=$v["id"]?>'  data-target="#deleteNode">删除</button>
				</div>
			</div>
		<?php } ?>
		</div>

	</div>
	<!--页码块-->
	<footer class="footer">
		<ul class="pagination">
			<li>
				<select id="page">
					<?php for ($i=1; $i <=$page->pageCount ; $i++) { 
						if ($i == $nowPage) {
						echo "<option selected>".$nowPage."</option>";
					}else{?>

						<option><?=$i?></option>
					<?php }} ?>
				</select>
				页
			</li>
			<li class="gray">
				共<?=$page->pageCount?>页
			</li>
			<?=LinkPager::widget(['pagination' =>$page])?>
		</ul>
	</footer>
	<script>
		$(function(){
			$("#page").change(function(){
				var page = $(this).val()
				location.href='http://www.lhl.com/nine/Part-time%20job/part-time/backend/web/index.php?w=node%2Fnode_lists&page='+page;
			})
		})
	</script>
	<!--增加权限弹出窗口-->
	<div class="modal fade" id="addNode" role="dialog" aria-labelledby="gridSystemModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="gridSystemModalLabel">添加权限</h4>
				</div>
				<div class="modal-body">
				<?php $form = ActiveForm::begin(['action' => ['add_node']])?>
					<div class="container-fluid">

					        <?= $form->field($NodeForm, 'name') ?>
					        <?= $form->field($NodeForm, 'controller') ?>
					        <?= $form->field($NodeForm, 'action') ?>
					        <?= $form->field($NodeForm, 'describe') ?>
					   
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn" data-dismiss="modal">取 消</button>
					<?= Html::submitButton('添加', ['class' => 'btn btn-primary']) ?>
				</div>
				 <?php ActiveForm::end(); ?>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->

	<!--修改权限弹出窗口-->
	<div class="modal fade" id="changeNode" role="dialog" aria-labelledby="gridSystemModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="gridSystemModalLabel">修改权限</h4>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<?php $form = ActiveForm::begin(['action' => ['node_update']])?>
							<?= Html::tag('input','',['type'=>'hidden' ,'','name'=>"id",'ID'=>'admin_node-id'])?>
					        <?= $form->field($NodeForm, 'name')->textInput(['id'=>'name']) ?>
					        <?= $form->field($NodeForm, 'controller')->textInput(['id'=>'controller']) ?>
					        <?= $form->field($NodeForm, 'action')->textInput(['id'=>'action']) ?>
					        <?= $form->field($NodeForm, 'describe')->textInput(['id'=>'describe']) ?>
					   
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn" data-dismiss="modal">取 消</button>
					<?= Html::submitButton('修改', ['class' => 'btn btn-primary']) ?>
				</div>
				 <?php ActiveForm::end(); ?>
	<script>
		$(function(){
			$(".update").click(function(){
				var node_id = $(this).attr('node_id')
				var _csrf  = $('input[name="_csrf"]').val()
				$('#admin_node-id').val(node_id);
				$.ajax({
					type:"post",
					url:"index.php?w=node/findone",
					data:{
						'_csrf':_csrf,
						'id':node_id
					},
					dataType:'json',
					success:function(data){
						if (data.error) {
							$('#name').val(data.msg.name)
							$('#controller').val(data.msg.controller)
							$('#action').val(data.msg.action)
							$('#describe').val(data.msg.describe)
							$('#admin_node-id').val(data.msg.id);
						}
						else{
							alert(data.msg)
						}
					}
				})
			})
		})
	</script>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->

	<!--弹出删除权限警告窗口-->
	<div class="modal fade" id="deleteNode" role="dialog" aria-labelledby="gridSystemModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title" id="gridSystemModalLabel">提示</h4>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<span id="del_content">确定要删除该权限？删除后不可恢复！</span>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
					<button type="button" class="btn btn-xs btn-danger true_delete" node_id=''>确 定</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
<script>
	$(function(){

		$(".delete").click(function(){
			var node_id = $(this).attr('node_id')
			$(".btn-danger").attr('node_id',node_id)
		})
		//隐藏提示框
		$('.btn-white').click(function(){
			$('#deleteNode').css("display","none;")
		})
		$(".true_delete").click(function(){
			$('#del_content').html('确定要删除该权限？删除后不可恢复！');
			var node_id = $(this).attr('node_id')
			var url = window.location.href;
			var _csrf  = $('input[name="_csrf"]').val()
			$.ajax({
				type:"post",
				url:"index.php?w=node/node_delete",
				data:{
					'_csrf':_csrf,
					'url':url,
					'node_id':node_id
				},
				dataType:"json",
				success:function(data){
					if (!data.error) {
						$('#del_content').html('删除失败！');
					}else{
						location.href=url;
					}
				}
			})
		})
	})
</script>